﻿// <copyright file="TestTrackSSME.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2010-06-14</date>
// <summary>Unit test for TrackSmoothStreamingMediaElement</summary>

namespace Test
{
    using System;
    using System.ComponentModel.Composition;
    using System.Windows;
    using System.Windows.Media;
    using Microsoft.Silverlight.Testing;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.WebAnalytics;

    /// <summary>
    /// Unit test for TrackSmoothStreamingMediaElement
    /// </summary>
    [TestClass]
    public class TestTrackSSME : SilverlightTest
    {
        #region Fields
        /// <summary>
        /// The SSME Test Page
        /// </summary>
        private SSMETestPage testPage;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the web analytics events
        /// </summary>
        [Import]
        public WebAnalyticsEvents Events { get; set; }
        #endregion

        /// <summary>
        /// Initialize the test page
        /// </summary>
        [TestInitialize]
        public void TestInitialize()
        {
            CompositionInitializer.SatisfyImports(this);

            this.testPage = new SSMETestPage();

            this.TestPanel.Children.Add(this.testPage);
        }

        /// <summary>
        /// Remove the test page
        /// </summary>
        [TestCleanup]
        public void TestCleanup()
        {
            this.TestPanel.Children.Remove(this.testPage);

            this.testPage = null;
        }

        /// <summary>
        /// Test the SSME Tracker
        /// </summary>
        [Asynchronous, TestMethod]
        public void TestSSME()
        {
            this.testPage.SSME.MediaOpened += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
            {
                this.testPage.SSME.Markers.Add(new TimelineMarker
                {
                    Text = "Ten seconds in",
                    Time = new TimeSpan(0, 0, 10),
                });
            });

            this.Events.TrackEvent += new EventHandler<AnalyticsEventArgs>(delegate(object sender, AnalyticsEventArgs e)
                {
                    EnqueueCallback(() => Assert.AreNotEqual("MediaFailed", e.AnalyticsEvent.Name));

                    switch (e.AnalyticsEvent.Name)
                    {
                        case "CurrentStateChanged":
                            EnqueueCallback(() => Assert.IsNotNull(e.AnalyticsEvent.ActionValue));
                            break;

                        case "ManifestReady":
                            break;

                        case "DownloadTrackChanged":
                            break;

                        case "MediaOpened":
                            break;

                        case "LogReady":
                            break;

                        case "VideoHighestPlayableTrackChanged":
                            break;

                        case "PlaybackTrackChanged":
                            break;

                        case "DownloadProgressChanged":
                            break;

                        case "MarkerReached":
                            EnqueueCallback(() => Assert.AreEqual("Ten seconds in", e.AnalyticsEvent.ActionValue));

                            this.EnqueueTestComplete();
                            break;

                        default:
                            System.Diagnostics.Debug.WriteLine(e.AnalyticsEvent.Name);
                            break;
                    }
                });
        }
    }
}